package com.amox.uitest.kit;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class FileKit {

	private final static FileKit kit = new FileKit();
	
	private FileKit() {}
	
	public static FileKit me() {
		return kit;
	}
	
	public String readAsString(File file) throws java.io.IOException 
	{
		StringBuffer fileData = new StringBuffer();
		BufferedReader reader = new BufferedReader(new FileReader(file));
		char[] buf = new char[1024];
		int numRead = 0;
		while ((numRead = reader.read(buf)) != -1) {
			String readData = String.valueOf(buf, 0, numRead);
			fileData.append(readData);
			buf = new char[1024];
		}
		reader.close();
		
		return fileData.toString();
	}
	
	public String readAsStssring(String filePath) throws java.io.IOException 
	{
		StringBuffer fileData = new StringBuffer();
		BufferedReader reader = new BufferedReader(new FileReader(filePath));
		char[] buf = new char[1024];
		int numRead = 0;
		while ((numRead = reader.read(buf)) != -1) {
			String readData = String.valueOf(buf, 0, numRead);
			fileData.append(readData);
			buf = new char[1024];
		}
		reader.close();
		
		return fileData.toString();
	}
	
	public String readAsString(FileReader fileReader) throws java.io.IOException 
	{
	    StringBuffer fileData = new StringBuffer();
	    BufferedReader reader = new BufferedReader(fileReader);
	    char[] buf = new char[1024];
	    int numRead = 0;
	    while ((numRead = reader.read(buf)) != -1) {
	        String readData = String.valueOf(buf, 0, numRead);
	        fileData.append(readData);
	        buf = new char[1024];
	    }
	    reader.close();
	    
	    return fileData.toString();
	}
}
